**********************
* OVERVIEW
*   This script generates tables and figures for the paper:
*       "What Do Workplace Wellness Programs Do? Evidence from the Illinois Workplace Wellness Study" (Damon Jones, David Molitor, and Julian Reif)
*   The macro $Wellness_WhatDoesWWDo should be defined to point to the main directory for the analysis
*	All do files are stored in /scripts
*   All raw data are stored in /data/raw
*   All tables are outputted to /results/tables
*   All figures are outputted to /results/figures
* 
* SOFTWARE REQUIREMENTS
*   Analyses run on Windows with at least 5 available cores using Stata version 14 and R-3.4.4
*   Install R-3.4.4 for Windows from https://cran.r-project.org/bin/windows/base/old/3.4.4/
*
* TO PERFORM A CLEAN RUN, DELETE THE FOLLOWING TWO FOLDERS:
*   /results
*   /data/proc
**********************

* User must define two global macros in order to run the analysis:
* (1) "Wellness_WhatDoesWWDo" points to the project folder
* (2) "RSCRIPT_PATH" points to R executable
* global Wellness_WhatDoesWWDo "C:/Users/jdoe/wellness"
* global RSCRIPT_PATH "C:/Program Files/R/R-3.4.4/bin/x64/Rscript.exe"

* Confirm that the globals for the project root directory and the R executable have been defined
assert !missing("$Wellness_WhatDoesWWDo")
assert !missing("$RSCRIPT_PATH")

* Log session
cap mkdir "$Wellness_WhatDoesWWDo/scripts/logs/"
cap log off
local datetime : di %tcCCYY.NN.DD!_HH.MM.SS `=clock("$S_DATE $S_TIME", "DMYhms")'
local logfile "$Wellness_WhatDoesWWDo/scripts/logs/_log_all_`datetime'.smcl"
log using "`logfile'"
di "Begin date and time: $S_DATE $S_TIME"

clear 
set more off
version 14
* All required add-ons are stored in the /packages and /auxiliary folders
adopath ++ "$Wellness_WhatDoesWWDo/scripts/packages"
adopath ++ "$Wellness_WhatDoesWWDo/scripts/auxiliary"
mata: mata mlib index

* Create directories for saving analysis output files
cap mkdir "$Wellness_WhatDoesWWDo/data/proc"
cap mkdir "$Wellness_WhatDoesWWDo/results"
cap mkdir "$Wellness_WhatDoesWWDo/results/figures"
cap mkdir "$Wellness_WhatDoesWWDo/results/intermediate_files"
cap mkdir "$Wellness_WhatDoesWWDo/results/tables"

* Run all project scripts
do "$Wellness_WhatDoesWWDo/scripts/1. clean_data.do"
do "$Wellness_WhatDoesWWDo/scripts/2. participation_balance.do"
do "$Wellness_WhatDoesWWDo/scripts/3. selection.do"
do "$Wellness_WhatDoesWWDo/scripts/4a. causal_effects_thru0717.do"
do "$Wellness_WhatDoesWWDo/scripts/4b. causal_effects_thru0119.do"
do "$Wellness_WhatDoesWWDo/scripts/4c. itt.do"
do "$Wellness_WhatDoesWWDo/scripts/5. make_figures.do"
texdoc do "$Wellness_WhatDoesWWDo/scripts/5b. make_figure1.do"
do "$Wellness_WhatDoesWWDo/scripts/6. supporting_calcs.do"

* End log
di "End date and time: $S_DATE $S_TIME"
log close

** EOF
